/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2021-10-07
 * Time: 13:59
 */
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) {
        this.val = val;
    }
    ListNode(int val, ListNode next) {
        this.val = val; this.next = next;
    }
 }
public class ReverseList {
    public ListNode reverseList(ListNode head){
        if(head==null){
            return null;
        }
        if(head.next==null){
            return head;
        }
        ListNode cur=head;
        ListNode newhead=null;
        while(cur!=null){
            ListNode curNext=cur.next;
            cur.next=newhead;
            newhead=cur;
            cur=curNext;
        }
        return newhead;
    }
}
